package movilmax.sia_corp.model;

import java.util.ArrayList;
import java.util.List;


import apli.conectar.Conectar;
import basedatos.Resultado;

public class CustomerDAO {

   
	
  public static List<Customer> getCustomers(List<Customer> list, int from, int to)
  {

    return list.subList(from, to);
  }

  public static Customer findById(List<Customer> list, int id)
  {

    for (Customer customer : list)
    {
      if (customer.getId() == id) return customer;
    }

    return null;
  }

  public static List<Customer> findNotById(List<Customer> list, int id, int from, int to)
  {
    List<Customer> sResult = new ArrayList<Customer>();

    for (Customer customer : list)
    {
      if (customer.getId() != id) sResult.add(customer);
    }

    return sResult.subList(from, to);
  }

  public static List<Customer> findGreaterAsId(List<Customer> list, int id, int from, int to)
  {
    List<Customer> sResult = new ArrayList<Customer>();

    for (Customer customer : list)
    {
      if (customer.getId() > id) sResult.add(customer);
    }

    return sResult.subList(from, to);
  }

  public static List<Customer> findLesserAsId(List<Customer> list, int id, int from, int to)
  {
    List<Customer> sResult = new ArrayList<Customer>();

    for (Customer customer : list)
    {
      if (customer.getId() < id) sResult.add(customer);
    }

    return sResult.subList(from, to);
  }

  public static Integer getCustomersCount(List<Customer> list)
  {

    return list.size();
  }

  public static List<Customer> cargar(int opc,String SQL){
      List<Customer> customers = new ArrayList<Customer>();
	  Conectar  BASE= new Conectar();
	    if(BASE.getMsg().equals("SI")){	
	    		 Resultado RCS=BASE.getBaseDatos().consultar(SQL);
	    		 if(RCS.RP){
	    			 do{
	    				Customer FILA=new Customer();
	    				FILA.setId(RCS.getInt("id") );
	    				switch(opc){
	    				    case 1:
	    				    	FILA.setCol1( RCS.getCadena("fecha") );
	    				    	FILA.setCol2( RCS.getCadena("hora") );
	    				    	FILA.setCol3( RCS.getCadena("des_actividad") );
	    				    	FILA.setCol4( RCS.getCadena("des_detalle") );
	    				    	FILA.setCol5( RCS.getCadena("obs") );
	    				    	FILA.setCol6( RCS.getCadena("usuario") );
	    					break;
	    				    case 2:
	    				    	FILA.setCol1( RCS.getCadena("fecha") );
	    				    	FILA.setCol2( RCS.getCadena("hora") );
	    				    	FILA.setCol3( RCS.getCadena("des_actividad") );
	    				    	FILA.setCol4( RCS.getCadena("des_detalle") );
	    				    	FILA.setCol5( RCS.getCadena("obs_operador") );
	    				    	FILA.setCol6( RCS.getCadena("obs_cliente") );
	    				    	FILA.setCol7( RCS.getCadena("area_usuario") );
	    				    	FILA.setCol8( RCS.getCadena("usuario") );
	    				    break;
	    				}
	    			  	customers.add(FILA);
	    			 }while(RCS.sigItem() );
	    	     }
	    } 	
       return customers;
   }
  
  
}
